﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;

namespace SqlMiM.Common.Trace
{
    public class InfoMessage
    {
        private SqlErrorCollection sqlErrorCollection;
        private Exception exception;
        private String message;
        private String source;


        /// <summary>
        /// internal constructor
        /// </summary>
        internal InfoMessage(SqlException exception)
        {
            this.message = exception.Message;
            this.sqlErrorCollection = exception.Errors;
            this.source = exception.Source;
            
        }

        /// <summary>
        /// internal constructor
        /// </summary>
        internal InfoMessage(SqlInfoMessageEventArgs args)
        {
            this.message = args.Message;
            this.sqlErrorCollection = args.Errors;
            this.source = args.Source;

        }

        /// <summary>
        /// internal constructor
        /// </summary>
        internal InfoMessage(Exception ex)
        {
            this.message = ex.Message;
            this.exception = ex;
            this.source = ex.Source;

        }

        /// <summary>
        /// The collection of warnings sent from the server.
        /// </summary>
        public SqlErrorCollection Errors
        {
            get
            {
                return this.sqlErrorCollection;
            }
        }

        /// <summary>
        /// The error
        /// </summary>
        public Exception Exception
        {
            get
            {
                return this.exception;
            }
        }

        /// <summary>
        /// Gets the full text of the error sent from the database.
        /// </summary>
        public string Message
        {
            get
            {
                return this.message;
            }
        }

        /// <summary>
        /// Gets the name of the object that generated the error.
        /// </summary>
        public string Source
        {
            get
            {
                return this.source;
            }
        }

        /// <summary>
        /// Retrieves a string representation of the System.Data.SqlClient.SqlConnection.InfoMessage
        /// </summary>
        public override string ToString()
        {
            return this.Message;
        }
    }

}
